<?php

namespace ms\modules\log\controllers;

use Yii;
use common\models\ModelLog;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
 * ModelLogController implements the CRUD actions for ModelLog model.
 */
class ModelLogController extends Controller
{
    /**
     * Lists all ModelLog models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new ModelLog();
        !isset($_GET['sort']) && $_GET['sort'] = '-log_time';
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }
    
    public function actionClear() {
    	ModelLog::deleteAll();
    	return $this->redirect(['index']);
    }

    /**
     * Displays a single ModelLog model.
     * @param integer $_id
     * @return mixed
     */
    public function actionView($id)
    {
//     	f_d($this->findModel($id));
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

   
    /**
     * Finds the ModelLog model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $_id
     * @return ModelLog the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = ModelLog::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
;